# frozen_string_literal: true

class RecreateIndexOnVulnerabilityReads < Gitlab::Database::Migration[2.1]
  OLD_INDEX_NAME = "index_vulnerability_reads_common_finder_query"
  NEW_INDEX_NAME = "index_vulnerability_reads_common_finder_query_2"

  disable_ddl_transaction!

  def up
    add_concurrent_index(
      :vulnerability_reads,
      %i[project_id state report_type severity vulnerability_id dismissal_reason],
      name: NEW_INDEX_NAME,
      order: { vulnerability_id: :desc }
    )
    remove_concurrent_index_by_name(
      :vulnerability_reads,
      OLD_INDEX_NAME
    )
  end

  def down
    add_concurrent_index(
      :vulnerability_reads,
      %i[project_id state report_type severity vulnerability_id],
      name: OLD_INDEX_NAME,
      order: { vulnerability_id: :desc }
    )
    remove_concurrent_index_by_name(
      :vulnerability_reads,
      NEW_INDEX_NAME
    )
  end
end
